import {defineStore} from "pinia";

export const useUserStore = defineStore('sys-user', {
    state: () => ({
        userInfo: {
            id: undefined,
            username: undefined,
            roles: [],
            permissions: [],
            menuTree: []
        }
    }),
    getters: {
        profileInitialized(state) {
            return state.userInfo.id
        },
        getRoles(state) {
            return state.userInfo.roles
        },
        getPermissions(state) {
            return state.userInfo.permissions
        },
        getMenuTree(state) {
            return state.userInfo.menuTree
        }
    },
    actions: {
        setUserInfo(userInfo) {
            this.userInfo = {
                id: userInfo.id,
                name: userInfo.username,
                roles: userInfo.rolePermissions,
                permissions: userInfo.permissions,
                menuTree: userInfo.menuTree
            }
        }
    }
})
